package com.zzy.cms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzy.cms.entity.CrmBanner;
import com.zzy.cms.service.CrmBannerService;
import com.zzy.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author KAZU
 * @since 2023-01-18
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {
	
	@Autowired
	private CrmBannerService bannerService;
	
	@ApiOperation(value = "分页查询banner")
	@GetMapping("pageBanner/{page}/{limit}")
	public R pageBanner(@PathVariable Long limit, @PathVariable Long page) {
		Page<CrmBanner> pageBanner = new Page<>(page, limit);
		bannerService.page(pageBanner, null);
		return R.ok().data("items", pageBanner.getRecords()).data("total", pageBanner.getTotal());
	}
	
	@ApiOperation(value = "添加Banner")
	@PostMapping("addBanner")
	public R addBanner(@RequestBody CrmBanner crmBanner) {
		bannerService.save(crmBanner);
		return R.ok();
	}
	
	@ApiOperation(value = "修改Banner")
	@PutMapping("update")
	public R updateById(@RequestBody CrmBanner crmBanner) {
		bannerService.updateById(crmBanner);
		return R.ok();
	}
	
	@ApiOperation(value = "删除Banner")
	@DeleteMapping("remove/{id}")
	public R removeBanner(@PathVariable String id) {
		bannerService.removeById(id);
		return R.ok();
	}
	
	@ApiOperation(value = "根据id查询Banner")
	@GetMapping("get/{id}")
	public R get(@PathVariable String id) {
		CrmBanner crmBanner = bannerService.getById(id);
		return R.ok().data("item", crmBanner);
	}
	

}


















